package com.nep.NEPG.datastructure;

import java.io.Serializable;
import java.util.Iterator;
import java.util.NoSuchElementException;

public class Queue<T> implements Iterable<T>, Serializable {
     private final LinkedList<T> list = new LinkedList<>();

     public void enqueue(T item) {
          list.add(item);
     }

     public T dequeue() {
          if (isEmpty()) {
               throw new NoSuchElementException("Queue is empty");
          }
          return list.removeFirst();
     }

     public T peek() {
          if (isEmpty()) {
               throw new NoSuchElementException("Queue is empty");
          }
          return list.get(0);
     }

     public int size() {
          return list.size();
     }

     public boolean isEmpty() {
          return list.isEmpty();
     }

     public void clear() {
          list.clear();
     }

     @Override
     public Iterator<T> iterator() {
          return list.iterator();
     }
}